//引入@reduxjs/toolkit
import {
    createSlice
} from '@reduxjs/toolkit'

const countSlice =createSlice({
    //action中的type的命名空间
    name:'counter',
    initialState:{
        count:0
    },
    reducers:{
        //函数的参数对应的是上一次的值和这一次的action对象
        //action对象中一个payload就是用户调用action函数时传递的值

        increasecount(prev,action){
                prev.count  += action.payload
        },
        decreasecount(prev,action){
                prev.count -= action.payload
        }

    }
})


export default countSlice.reducer
//暴露actions
export  const {
    increasecount,
    decreasecount
}=countSlice.actions